<?php

use yii\db\Schema;
use yii\db\Migration;

class m160127_055742_topic extends Migration
{
    const TB_NAME='topic';
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%'.self::TB_NAME.'}}', [
            'id' => $this->primaryKey(),
            'topic_name' => $this->string()->notNull()->unique(),
            'topic_author' => $this->string()->notNull(),
            'topic_des' => $this->string()->notNull(),
            'topic_tags' => $this->string()->notNull(),
            'created_at' => $this->integer()->notNull(),
            'updated_at' => $this->integer(),
            'topic_node_time' => $this->integer()->notNull(),
            'topic_node_index' => $this->integer()->notNull(),
            'topic_viewcount' => $this->integer()->defaultValue(0),
            'topic_comment_id' => $this->smallInteger(),
            'topic_recommend_id' => $this->smallInteger(),
        ], $tableOptions);
    }

    public function safeDwon()
    {
        $this->dropTable('{{%'.self::TB_NAME.'}}');
    }
}
